package com.yc.yyds.dao;

import com.yc.yyds.util.DBHelper;

import java.util.List;
import java.util.Map;

public class SaveIndentDao {

    public void  saveIndent(String userid,String ppjhid,String seat,String money){
        String sql = "insert into indent values(null,?,?,?,default,?,default)";
        DBHelper.update(sql,userid,ppjhid,seat,money);
    }

    public Map<String, Object> countSeat(String ppjhid){
        String sql ="select remainseats from arrange where ppjhid = ?";
        return DBHelper.selectOneMap(sql,ppjhid);
    }
    public void updateIndent(String ppjhid,int remainseats){
        String sql ="update arrange set remainseats = ?  where ppjhid=?";
        DBHelper.update(sql,remainseats,ppjhid);
    }
    public void updataUserMoney(String userid,float money){
        String sql = "update user set money = ? where userid =? ";
        DBHelper.update(sql,money,userid);
    }
    //查询作为
    public List<Map<String, Object>> querySeats(String ppjhid){
        String sql ="select seat from indent where ppjhid=?";
        return DBHelper.selectListMap(sql,ppjhid);
    }
    //确认支付订单
    public void queren(String indentid){
        String sql =" update indent set ispay = 1 where indentid = ?";
        DBHelper.update(sql,indentid);
    }
    //查订单信息
    public Map<String,Object> query(){
        String sql ="select indentid,indenttime,moviename,starttime,userid FROM  indent i " +
                "INNER JOIN arrange a  ON a.ppjhid=i.ppjhid " +
                "inner join movie m on a.movieid=m.movieid order by i.indenttime desc LIMIT 0,1";
        return DBHelper.selectOneMap(sql);
    }
}
